﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 通讯录
{
    public partial class Form2 : Form
    {
        PeoInfo peo;
        public Form2()
        {
            InitializeComponent();
        }

        public Form2(PeoInfo Peo)
        {
            InitializeComponent();
            
            nameTextBox.Text = Peo.getName;
            sexComboBox.SelectedItem = Peo.getSex;
            teleTextBox.Text = Peo.getTele;
            string[] addr = Peo.getAddr.Split('/');
            comboBox1.SelectedItem = addr[0];
            comboBox2.SelectedItem = addr[1];
            comboBox3.SelectedItem = addr[2];
            birthdateTimePicker.Value = Peo.getBirthDate;

        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(comboBox2.Text == "广州市")
            {
                List<string> town = new List<string>();
                town.Add("荔湾区");
                town.Add("越秀区");
                town.Add("海珠区");
                town.Add("天河区");
                town.Add("白云区");
                town.Add("黄埔区");
                town.Add("番禺区");
                town.Add("花都区");
                town.Add("增城区");
                town.Add("从化区");
                town.Add("南沙区");
                town.Add("萝岗区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "韶关市")
            {
                List<string> town = new List<string>();
                town.Add("武江区");
                town.Add("浈江区");
                town.Add("曲江区");
                town.Add("始兴县");
                town.Add("仁化县");
                town.Add("翁源县");
                town.Add("乳源瑶族自治县");
                town.Add("新丰县");
                town.Add("乐昌县");
                town.Add("南雄县");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "深圳市")
            {
                List<string> town = new List<string>();
                town.Add("罗湖区");
                town.Add("福田区");
                town.Add("南山区");
                town.Add("宝安区");
                town.Add("龙岗区");
                town.Add("盐田区");
                town.Add("光明区");
                town.Add("坪山区");
                town.Add("龙华区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "珠海市")
            {
                List<string> town = new List<string>();
                town.Add("香洲区");
                town.Add("斗门区");
                town.Add("金湾区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "汕头市")
            {
                List<string> town = new List<string>();
                town.Add("龙湖区");
                town.Add("金平区");
                town.Add("濠江区");
                town.Add("潮阳区");
                town.Add("潮南区");
                town.Add("澄海区");
                town.Add("南澳县");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "佛山市")
            {
                List<string> town = new List<string>();
                town.Add("禅城区");
                town.Add("南海区");
                town.Add("顺德区");
                town.Add("三水区");
                town.Add("高明区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "江门市")
            {
                List<string> town = new List<string>();
                town.Add("蓬江区");
                town.Add("江海区");
                town.Add("新会区");
                town.Add("台山市");
                town.Add("开平区");
                town.Add("鹤山市");
                town.Add("恩平市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "湛江市")
            {
                List<string> town = new List<string>();
                town.Add("赤坎区");
                town.Add("霞山区");
                town.Add("坡头区");
                town.Add("麻章区");
                town.Add("遂溪县");
                town.Add("徐闻县");
                town.Add("廉江市");
                town.Add("雷州市");
                town.Add("吴川市");
                town.Add("开发区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "茂名市")
            {
                List<string> town = new List<string>();
                town.Add("茂南区");
                town.Add("电白区");
                town.Add("高州市");
                town.Add("化州市");
                town.Add("信宜市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "肇庆市")
            {
                List<string> town = new List<string>();
                town.Add("端州区");
                town.Add("鼎湖区");
                town.Add("广宁县");
                town.Add("怀集县");
                town.Add("封开县");
                town.Add("德庆县");
                town.Add("高要区");
                town.Add("四会市");
                town.Add("高新技术产业开发区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "惠州市")
            {
                List<string> town = new List<string>();
                town.Add("惠城区");
                town.Add("惠阳区");
                town.Add("博罗县");
                town.Add("惠东县");
                town.Add("龙门县");
                town.Add("仲恺高新区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "梅州市")
            {
                List<string> town = new List<string>();
                town.Add("梅江区");
                town.Add("梅县区");
                town.Add("大埔县");
                town.Add("丰顺县");
                town.Add("五华县");
                town.Add("平远县");
                town.Add("蕉岭县");
                town.Add("兴宁市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "汕尾市")
            {
                List<string> town = new List<string>();
                town.Add("城区");
                town.Add("陆丰市");
                town.Add("海丰县");
                town.Add("陆河县");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "河源市")
            {
                List<string> town = new List<string>();
                town.Add("源城区");
                town.Add("紫金县");
                town.Add("龙川县");
                town.Add("连平县");
                town.Add("和平县");
                town.Add("东源县");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "阳江市")
            {
                List<string> town = new List<string>();
                town.Add("江城区");
                town.Add("阳西县");
                town.Add("阳东区");
                town.Add("阳春市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "潮州市")
            {
                List<string> town = new List<string>();
                town.Add("湘桥区");
                town.Add("潮安区");
                town.Add("饶平县");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "揭阳市")
            {
                List<string> town = new List<string>();
                town.Add("榕城区");
                town.Add("揭东区");
                town.Add("揭西县");
                town.Add("惠来县");
                town.Add("普宁市");
                town.Add("东山区");
                town.Add("普侨区");
                town.Add("大南山侨区");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "云浮市")
            {
                List<string> town = new List<string>();
                town.Add("云城区");
                town.Add("新兴县");
                town.Add("郁南县");
                town.Add("云安区");
                town.Add("罗定市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "东莞市")
            {
                List<string> town = new List<string>();
                town.Add("南城街道");
                town.Add("石龙镇");
                town.Add("长安镇");
                town.Add("虎门镇");
                town.Add("横沥镇");
                town.Add("寮步镇");
                town.Add("黄江镇");
                town.Add("清溪镇");
                town.Add("莞城街道");
                town.Add("万江街道");
                town.Add("东城街道");
                town.Add("石碣镇");
                town.Add("茶山镇");
                town.Add("石排镇");
                town.Add("企石镇");
                town.Add("桥头镇");
                town.Add("谢岗镇");
                town.Add("东坑镇");
                town.Add("常平镇");
                town.Add("大朗镇");
                town.Add("塘厦镇");
                town.Add("凤岗镇");
                town.Add("厚街镇");
                town.Add("沙田镇");
                town.Add("道滘镇");
                town.Add("洪梅镇");
                town.Add("麻涌镇");
                town.Add("中堂镇");
                town.Add("高埗镇");
                town.Add("樟木头镇");
                town.Add("大岭山镇");
                town.Add("望牛墩镇");
                town.Add("东莞市");
                comboBox3.DataSource = town;
            }
            else if (comboBox2.Text == "中山市")
            {
                List<string> town = new List<string>();
                town.Add("中山市");
                comboBox3.DataSource = town;
            }
        }

        private void submitButton_Click(object sender, EventArgs e)
        {
            try
            {
                string addr = comboBox1.SelectedItem.ToString()+ '/' + comboBox2.SelectedItem.ToString() + '/' + comboBox3.SelectedItem.ToString();
                peo = new PeoInfo(nameTextBox.Text, sexComboBox.SelectedItem.ToString(), teleTextBox.Text, addr, birthdateTimePicker.Value);
                this.DialogResult = DialogResult.OK;
            }
            catch (NullReferenceException)
            {
                MessageBox.Show("请填写完整信息" , "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        public PeoInfo PeoInfo { 
            get { 
                return peo; 
            }
        }
    }
}
